<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    #box {
      width: 1000px;
      height: 200px;
      /* background-color: aqua; */
      margin: 0 auto;
      font-size: 24px;
      line-height: 200px;
      text-align: center;
    }
  </style>
</head>

<body>
  <div id='box'></div>
</body>
<script>
  // 距离十一放假还有多少天xx小时xx分xx秒

  var box = document.querySelector("#box");
  // console.log(box);



  function getTime(date) {
    var now = new Date();
    // console.log(now);
    var future = new Date(date)
    // console.log(future);
    var t = future - now;
    // console.log(t);

    var time = parseInt(t / 1000);
    console.log(time);

    var day = parseInt(time / (24 * 60 * 60));
    console.log(day);

    var hour = parseInt(time / (60 * 60)) % 24;
    console.log(hour);

    var minute = parseInt(time / 60) % 60;
    console.log(minute);

    var second = time % 60;
    console.log(second);

    box.innerHTML = `距离国庆放假还有${day}天${hour}小时${minute}分${second}秒`;

  }
  getTime("2021-10-1");

  // var timer = setInterval(function () {
  //   getTime("2021-10-1");

  // }, 1000);

  // setInterval(getTime, 1000, "2021-10-1");

  var timer = setInterval('getTime("2021-10-1")', 1000)
</script>

</html>